<?php
/**
 * Frontcontroller plugin for Zend Layout
 * 
 * @author hcderaad
 * @package eventicms
 */
class EICms_Controller_Plugin_Layout extends Zend_Layout_Controller_Plugin_Layout {
	
	/**
	 * Perform preDispatch operations
	 *
	 * @param Zend_Controller_Request_Abstract $request
	 */
	public function preDispatch(Zend_Controller_Request_Abstract $request) {
		switch($request->getModuleName()) {
			case 'admin' :
				$this->changeModule('admin');
		}
		
		$view = $this->getLayout()->getView();
		
		$baseUrl = (!empty(Bootstrap::$registry->config->bootstrap->base_domain)) ?
					Bootstrap::$registry->config->bootstrap->base_domain : '';
		$baseUrl .= Zend_Controller_Front::getInstance()->getBaseUrl();
		$view->headLink()->appendStylesheet($baseUrl . "/css/blueprint/screen.css","screen,projection")
					->appendStylesheet($baseUrl . "/css/blueprint/print.css","print")
					->appendStylesheet($baseUrl . "/css/style.css","screen,projection")
					->appendStylesheet($baseUrl . "/css/blueprint/ie.css","screen,projection","ie");
	}
	
	/**
	 * Change the modulespecific layouts.
	 *
	 * @param string $moduleName
	 */
	public function changeModule($moduleName) {
		$layoutPath = $this->getLayout()->getLayoutPath();
		if(strpos($layoutPath,$moduleName) === FALSE) {
			$this->getLayout()->setLayoutPath(
				dirname(dirname(
					$this->getLayout()->getLayoutPath()
				))
				. DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $moduleName . '/views/layouts'
				);
		}
		$this->getLayout()->setLayout($moduleName);
	}
}
?>